import Foundation
import SwiftUI

// 目标类型
enum ObjectType: String, CaseIterable, Identifiable {
    case person = "行人"
    case car = "车辆"
    case animal = "动物"
    case obstacle = "障碍物"
    case face = "人脸"
    case unknown = "未知"
    
    var id: String { self.rawValue }
    
    var color: Color {
        switch self {
        case .person:
            return .green
        case .car:
            return .blue
        case .animal:
            return .orange
        case .obstacle:
            return .red
        case .face:
            return .purple
        case .unknown:
            return .gray
        }
    }
}

// 目标行为
enum ObjectBehavior: String, CaseIterable, Identifiable {
    case walking = "步行"
    case running = "跑步"
    case standing = "静止"
    case sitting = "坐下"
    case moving = "移动"
    case unknown = "未知"
    
    var id: String { self.rawValue }
}

// 目标状态
enum TrackingStatus: String, CaseIterable, Identifiable {
    case tracking = "跟踪中"
    case lost = "已丢失"
    case found = "已发现"
    case inactive = "未激活"
    
    var id: String { self.rawValue }
    
    var color: Color {
        switch self {
        case .tracking:
            return .green
        case .lost:
            return .red
        case .found:
            return .blue
        case .inactive:
            return .gray
        }
    }
}

// 识别目标模型
struct DetectedObject: Identifiable {
    let id: UUID
    var type: ObjectType
    var confidence: Double // 置信度 0.0-1.0
    var distance: Double // 距离（米）
    var behavior: ObjectBehavior
    var trackingStatus: TrackingStatus
    var boundingBox: CGRect // 边界框坐标
    var detectedTime: Date
    var lastUpdatedTime: Date
    
    // 格式化的置信度（百分比）
    var confidenceString: String {
        return "\(Int(confidence * 100))%"
    }
    
    // 格式化的距离
    var distanceString: String {
        return String(format: "%.1f米", distance)
    }
    
    init(id: UUID = UUID(), type: ObjectType, confidence: Double, distance: Double, behavior: ObjectBehavior, trackingStatus: TrackingStatus, boundingBox: CGRect, detectedTime: Date = Date(), lastUpdatedTime: Date = Date()) {
        self.id = id
        self.type = type
        self.confidence = confidence
        self.distance = distance
        self.behavior = behavior
        self.trackingStatus = trackingStatus
        self.boundingBox = boundingBox
        self.detectedTime = detectedTime
        self.lastUpdatedTime = lastUpdatedTime
    }
}

// 示例数据
extension DetectedObject {
    static var sample: DetectedObject {
        return DetectedObject(
            type: .person,
            confidence: 0.89,
            distance: 2.4,
            behavior: .walking,
            trackingStatus: .tracking,
            boundingBox: CGRect(x: 0.2, y: 0.3, width: 0.4, height: 0.3)
        )
    }
} 